package com.hang.ad.index.adplan;

import com.hang.ad.index.IndexAware;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class AdPlanIndex implements IndexAware<Long, AdPlanObject> {
    private static Map<Long, AdPlanObject> map;
    static {
        map = new ConcurrentHashMap<Long, AdPlanObject>();
    }
    public AdPlanObject get(Long key) {

        return map.get(key);
    }

    public void update(Long key, AdPlanObject value) {
        AdPlanObject adPlanObject = map.get(key);
        if (adPlanObject == null){
            map.put(key, value);
        }else {
            adPlanObject.update(value);
        }
    }

    public void add(Long key, AdPlanObject value) {
        map.put(key, value);
    }

    public void delete(Long key, AdPlanObject value) {
        map.remove(key);
    }
}
